home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_097 / graphit / window.c < prev   
C/C++ Source or Header  |  1992-05-06  |  21KB  |  762 lines

  1. /****************************************************************************/
  2. /*   Program: Graph It II    (The C Program)                                    */
  3. /*   SubModule:    window.c  1-20-87                                            */
  4. /*   CopyRight By Flynn D. Fishman  January 1987                            */
  5. /*    Feel Free to copy and alter this source                                    */
  6. /****************************************************************************/
  7. /*    This module contains some of the more "primitive" graphic routines such
  8.      as Line, DrawImages, DrawWindow                                        */
  9.  
  10. #include "graph.h"
  11. #define MAXMENU 2
  12. struct Menu menu[MAXMENU];
  13.  
  14. /* Image data structures (Icons)    */
  15. USHORT Move_Icon[] =
  16.     {
  17.     0xffff, 0x8001, 0x8001, 0x8181, 0x8d81, 0x8db1, 0x8db1, 0xedb5, 0xeffd,
  18.     0xbffd, 0x9ffd, 0x8ff1, 0x8001, 0x8001, 0xffff, 
  19.     0xffff,        /* 1111 1111 1111 1111 */
  20.     0x8001,        /* 1--- ---- ---- ---1 */
  21.     0x8001,        /* 1--- ---- ---- ---1 */
  22.     0x8001,        /* 1--- ---2 2--- ---1 */
  23.     0x8001,        /* 1--- 22-2 2--- ---1 */
  24.     0x8001,        /* 1--- 22-2 2-22 ---1 */
  25.     0x8001,        /* 1--- 22-2 2-22 ---1 */
  26.     0x8001,        /* 122- 22-2 2-22 -2-1 */
  27.     0x8001,        /* 122- 2222 2222 22-1 */
  28.     0x8001,        /* 1-22 2222 2222 22-1 */
  29.     0x8001,        /* 1--2 2222 2222 22-1 */
  30.     0x8001,        /* 1--- 2222 2222 2--1 */
  31.     0x9ffd,        /* 1--3 3333 3333 33-1 */
  32.     0x9ffd,        /* 1--3 3333 3333 33-1 */
  33.     0xffff        /* 1111 1111 1111 1111 */
  34.     };
  35.  
  36. USHORT Zoom_Icon[] =
  37.     {
  38.     0xffff, 0x8001,  0x83c1,  0x8661,  0x8c31,  0x8c31,  0x8661, 
  39.     0x83c1, 0x8181,  0x8181,  0x8181,  0x8181,  0x8181,  0x8001,  0xffff, 
  40.     0xffff,        /* 1111 1111 1111 1111 */
  41.     0x8001,        /* 1--- ---- ---- ---1 */
  42.     0x8001,        /* 1--- --33 33-- ---1 */
  43.     0x8001,        /* 1--- -332 233- ---1 */
  44.     0x8001,        /* 1--- 33-- 2233 ---1 */
  45.     0x8001,        /* 1--- 33-- -233 ---1 */
  46.     0x8001,        /* 1--- -33- -33- ---1 */
  47.     0x8001,        /* 1--- --33 33-- ---1 */
  48.     0x8001,        /* 1--- ---3 3--- ---1 */
  49.     0x8001,        /* 1--- ---3 3--- ---1 */
  50.     0x8001,        /* 1--- ---2 2--- ---1 */
  51.     0x8001,        /* 1--- ---3 3--- ---1 */
  52.     0x8001,        /* 1--- ---3 3--- ---1 */
  53.     0x8001,        /* 1--- ---- ---- ---1 */
  54.     0xffff,        /* 1111 1111 1111 1111 */
  55.     };
  56.  
  57. USHORT Command_Icon[] =
  58.     {
  59.     0xffff, 0x8001, 0x8001, 0xe0c1, 0xe0c1, 0xb19f, 0x9b1f, 0x8e01, 
  60.     0x8c1f, 0x8c1f, 0x8c01, 0x8c01, 0x8001, 0x8001, 0xffff, 
  61.     0xffff,        /* 1111 1111 1111 1111 */
  62.     0x8001,        /* 1--- ---- ---- ---1 */
  63.     0x8001,        /* 1--- ---- ---- ---1 */
  64.     0x8001,        /* 122- ---- 22-- ---1 */
  65.     0x8001,        /* 122- ---- 22-- ---1 */
  66.     0x8001,        /* 1-22 ---2 2--2 2221 */
  67.     0x8001,        /* 1--2 2-22 ---2 2221 */
  68.     0x8001,        /* 1--- 222- ---- ---1 */
  69.     0x8001,        /* 1--- 22-- ---2 2221 */
  70.     0x8001,        /* 1--- 22-- ---2 2221 */
  71.     0x8001,        /* 1--- 22-- ---- ---1 */
  72.     0x8001,        /* 1--- 22-- ---- ---1 */
  73.     0x8001,        /* 1--- ---- ---- ---1 */
  74.     0x8001,        /* 1--- ---- ---- ---1 */
  75.     0xffff        /* 1111 1111 1111 1111 */
  76.     };
  77.  
  78. USHORT Help_Icon[] =
  79.     {
  80.     0xffff, 0x8001, 0x83e1, 0x87e1, 0x8c71, 0x80e1, 0x80e1, 0x81c1, 
  81.     0x81c1, 0x8001, 0x8081, 0x81c1, 0x8081, 0x8001, 0xffff, 
  82.     0xffff,        /* 1111 1111 1111 1111 */
  83.     0x8001,        /* 1--- ---- ---- ---1 */
  84.     0x8001,        /* 1--- --22 222- ---1 */
  85.     0x8001,        /* 1--- -222 2222 ---1 */
  86.     0x8001,        /* 1--- 22-- -222 ---1 */
  87.     0x8001,        /* 1--- ---- 222- ---1 */
  88.     0x8001,        /* 1--- ---- 222- ---1 */
  89.     0x8001,        /* 1--- ---2 22-- ---1 */
  90.     0x8001,        /* 1--- ---2 22-- ---1 */
  91.     0x8001,        /* 1--- ---- ---- ---1 */
  92.     0x8001,        /* 1--- ---- 2--- ---1 */
  93.     0x8001,        /* 1--- ---2 22-- ---1 */
  94.     0x8001,        /* 1--- ---- 2--- ---1 */
  95.     0x8001,        /* 1--- ---- ---- ---1 */
  96.     0xffff,        /* 1111 1111 1111 1111 */
  97.     };
  98.  
  99. USHORT Hidden_Icon[] =
  100.     {
  101.     0xffff, 0x8001, 0x8001, 0x8001, 0x83cf, 0x8301, 0x8301, 0x8301, 
  102.     0x8001, 0x8301, 0x8301, 0x8301, 0x83ff, 0x8001, 0xffff, 
  103.     0xffff,        /* 1111 1111 1111 1111 */
  104.     0x8001,        /* 1--- ---- ---- ---1 */
  105.     0xbff1,        /* 1-22 2222 2222 ---1 */
  106.     0xb031,        /* 1-22 ---- --22 ---1 */
  107.     0xb03f,        /* 1-22 --11 1122 3331 */
  108.     0xb031,        /* 1-22 --11 --22 ---1 */
  109.     0xb031,        /* 1-22 --11 --22 ---1 */
  110.     0xb031,        /* 1-22 --11 --22 ---1 */
  111.     0xbff1,        /* 1-22 2222 2222 ---1 */
  112.     0x8301,        /* 1--- --33 ---- ---1 */
  113.     0x8301,        /* 1--- --33 ---- ---1 */
  114.     0x8301,        /* 1--- --33 ---- ---1 */
  115.     0x83ff,        /* 1--- --33 3333 3331 */
  116.     0x8001,        /* 1--- ---- ---- ---1 */
  117.     0xffff,        /* 1111 1111 1111 1111 */
  118.     };
  119.  
  120. USHORT Home_Icon[] =
  121.     {
  122.     0xffff, 0x8181, 0x8181, 0x8181, 0x8181, 0x8181, 0x8181, 0xffff, 0x8181,
  123.     0x8181, 0x8181, 0x8181, 0x8181, 0x8181, 0xffff,
  124.     0xffff,        /* 1111 1111 1111 1111 */
  125.     0x8001,        /* 1--- ---2 2--- ---1 */
  126.     0x8001,        /* 1--- ---2 2--- ---1 */
  127.     0x8001,        /* 1--- ---2 2--- ---1 */
  128.     0x8001,        /* 1--- ---2 2--- ---1 */
  129.     0x8001,        /* 1--- ---2 2--- ---1 */
  130.     0x8001,        /* 1--- ---2 2--- ---1 */
  131.     0x8001,        /* 1222 2222 2222 2221 */
  132.     0x8001,        /* 1--- ---2 2--- ---1 */
  133.     0x8001,        /* 1--- ---2 2--- ---1 */
  134.     0x8001,        /* 1--- ---2 2--- ---1 */
  135.     0x8001,        /* 1--- ---2 2--- ---1 */
  136.     0x8001,        /* 1--- ---2 2--- ---1 */
  137.     0x8001,        /* 1--- ---2 2--- ---1 */
  138.     0xffff        /* 1111 1111 1111 1111 */
  139.     };
  140.  
  141. USHORT Quit_Icon[] =
  142.     {
  143.     0xffff, 0x8001, 0x83c1, 0x8661, 0x8c31, 0x8c31, 0x9819, 0x9819, 0x9999,
  144.     0x9db9, 0x8cf1, 0x8679, 0x83cd, 0x8001, 0xffff,
  145.     0xffff,        /* 1111 1111 1111 1111 */
  146.     0x8001,        /* 1--- ---- ---- ---1 */
  147.     0x8001,        /* 1--- --22 22-- ---1 */
  148.     0x8001,        /* 1--- -22- -22- ---1 */
  149.     0x8001,        /* 1--- 22-- --22 ---1 */
  150.     0x8001,        /* 1--- 22-- --22 ---1 */
  151.     0x8001,        /* 1--2 2--- ---2 2--1 */
  152.     0x8001,        /* 1--2 2--- ---2 2--1 */
  153.     0x8001,        /* 1--2 2--2 2--2 2--1 */
  154.     0x8001,        /* 1--- 22-2 2-22 ---1 */
  155.     0x8001,        /* 1--- 22-- 2222 ---1 */
  156.     0x8001,        /* 1--- -22- -222 2--1 */
  157.     0x8001,        /* 1--- --22 22-- 22-1 */
  158.     0x8001,        /* 1--- ---- ---- ---1 */
  159.     0xffff        /* 1111 1111 1111 1111 */
  160.     };
  161.  
  162. #define BALLHEIGHT  5
  163. #define BALLWIDTH    6
  164.  
  165. struct Image Icons =
  166.     {
  167.     0,0,            /* left Top                    */
  168.     16, ICONY, 2,    /* width hieght, depth        */
  169.     &Move_Icon[0],    /* image date                */
  170.     0x3, 0x0,        /* PlanePick, PlaneOnOff    */
  171.     NULL,            /* Next Image                */
  172.     };
  173.  
  174. struct IntuitionBase *IntuitionBase;
  175. struct GfxBase *GfxBase;
  176.  
  177. struct TextAttr MyFont =
  178.   {
  179.    "topaz.font",              /* Font Name        */
  180.    TOPAZ_SIXTY,               /* Font Height      */
  181.    FS_NORMAL,                 /* Style            */
  182.    FPF_ROMFONT,               /* Preferences      */
  183.   };
  184.  
  185. struct NewWindow NewWindow =
  186.     {
  187.     0l,
  188.     0l,
  189.     XSIZE,
  190.     YSIZE,
  191.     0l,
  192.     1l,
  193.     CLOSEWINDOW | MOUSEMOVE | MOUSEBUTTONS | MENUPICK
  194.     | NEWSIZE | INACTIVEWINDOW | SIZEVERIFY,
  195.     WINDOWCLOSE | SMART_REFRESH | ACTIVATE | WINDOWDRAG
  196.     | WINDOWDEPTH | WINDOWSIZING | REPORTMOUSE,
  197.     NULL,
  198.     NULL,
  199.     "Graph It II  Beta 1.0  By Flynn D. Fishman", 
  200.     NULL,
  201.     NULL,
  202.     100l, 35l,
  203.     NULL, NULL,
  204.     WBENCHSCREEN,
  205.     };
  206.  
  207. openstuff()
  208.     {
  209.     struct Window *Window;
  210.  
  211.     IntuitionBase = (struct IntuitionBase *)
  212.                             OpenLibrary("intuition.library", INTUITION_REV);
  213.     if( IntuitionBase == NULL )
  214.         {
  215.         printf("Error: opening Intuition\n");
  216.         exit(FALSE); 
  217.         }
  218.  
  219.     GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",GRAPHICS_REV);
  220.     if( GfxBase == NULL )
  221.         {
  222.         printf("Error: opening graphics\n");
  223.         exit(FALSE);
  224.         }
  225.  
  226.     if(( Window = (struct Window *)OpenWindow(&NewWindow) ) == NULL)
  227.         {
  228.         printf("Error: opening window\n");
  229.         exit(FALSE);
  230.         }
  231.  
  232.     InitMenu();
  233.     SetMenuStrip( Window, &menu[0] );
  234.  
  235.     return(Window);
  236.     }
  237.  
  238. closestuff(Window)
  239. struct Window *Window;
  240.     {
  241.     if (Window != NULL)
  242.         {
  243.         CloseWindow( Window );
  244.         ClearMenuStrip( Window );
  245.         }
  246.     }
  247.  
  248. DrawWindow(Window, parameters)
  249. struct Window *Window;
  250. struct Graph_Parameters *parameters;
  251.     {
  252.     long int minx, miny, maxx, maxy;
  253.     long int y;
  254.     char line[80];
  255.  
  256.     minx = Window->BorderLeft;
  257.     miny = Window->BorderTop;
  258.     maxx = Window->Width - Window->BorderRight - XBORDER;
  259.     maxy = Window->Height - Window->BorderBottom - YBORDER;
  260.  
  261.     ClearWindow(Window);
  262.  
  263. /* Place the data        */
  264.     SetAPen(Window->RPort, 3);
  265.  
  266.     Move(Window->RPort, minx, maxy + 9);
  267.     sprintf(line,"%2.2f", parameters->xstart);
  268.     Text(Window->RPort, line, strlen(line) );
  269.  
  270.     Move(Window->RPort, maxx - XEXPANDX + 3, maxy + 9);
  271.     sprintf(line,"%2.2f", parameters->xend);
  272.     Text(Window->RPort, line, strlen(line) );
  273.  
  274.     Move(Window->RPort, maxx, maxy - YEXPANDY + 9);
  275.     sprintf(line,"%3.0f", parameters->ystart);
  276.     Text(Window->RPort, line, strlen(line) );
  277.  
  278.     Move(Window->RPort, maxx, miny + 9);
  279.     sprintf(line,"%3.0f", parameters->yend);
  280.     Text(Window->RPort, line, strlen(line) );
  281.  
  282. /* Draw the Graph rectangle area    */
  283.     DrawRectangle(Window, 1, minx, miny, maxx, maxy);
  284. /* Draw the X-Expand area            */
  285.     DrawRectangle(Window, 3, minx + XEXPANDX, maxy + 2,
  286.                              maxx - XEXPANDX, maxy + XEXPANDY);
  287. /* Draw the Y-Expand area            */
  288.     DrawRectangle(Window, 3, maxx + 2, miny + YEXPANDY,
  289.                              maxx + YEXPANDX, maxy - YEXPANDY);
  290. /* Draw the Icon Area                */
  291.     for (y = miny + YEXPANDY; y < maxy - YEXPANDX - ICONY; y += ICONY + 2)
  292.         DrawRectangle(Window, 3, maxx + YEXPANDX + 2, y,
  293.                                  maxx + XBORDER  - 1, y + ICONY); 
  294.  
  295.     DrawImages(Window, maxx + YEXPANDX + 2, miny + YEXPANDY);
  296.     DrawButton(Window, minx + XEXPANDX + 1, maxy + 3);
  297.     DrawButton(Window, maxx + 3, maxy - YEXPANDY - BALLHEIGHT - 1 );
  298.     }
  299.  
  300. ClearWindow(Window)
  301. struct Window *Window;
  302.     {
  303.     long int minx, miny, maxx, maxy;
  304.  
  305.     minx = Window->BorderLeft;
  306.     miny = Window->BorderTop;
  307.     maxx = Window->Width - Window->BorderRight;
  308.     maxy = Window->Height - Window->BorderBottom;
  309.  
  310.     SetAPen(Window->RPort, 0l);
  311.     SetOPen(Window->RPort, 0l);
  312.     SetDrMd(Window->RPort, JAM2);
  313.     RectFill(Window->RPort, minx, miny, maxx, maxy);
  314.     }
  315.  
  316.  
  317. DrawRectangle(Window, colour, x1, y1, x2, y2)
  318. struct Window *Window;
  319. long int colour, x1, y1, x2, y2;
  320.     {
  321.     long int minx, miny, maxx, maxy;
  322.  
  323.     minx = Window->BorderLeft;
  324.     miny = Window->BorderTop;
  325.     maxx = Window->Width - Window->BorderRight;
  326.     maxy = Window->Height - Window->BorderBottom;
  327.  
  328.     x1 = (x1 < minx) ? minx : x1;
  329.     y1 = (y1 < miny) ? miny : y1;
  330.     x2 = (x2 > maxx) ? maxx : x2;
  331.     y2 = (y2 > maxy) ? maxy : y2;
  332.  
  333.     if (x1 > x2) return(FALSE);
  334.     if (y1 > y2) return(FALSE);
  335.  
  336.     SetDrMd(Window->RPort, JAM2);
  337.     SetOPen(Window->RPort, colour);
  338.     SetAPen(Window->RPort, 0l);
  339.     RectFill(Window->RPort, x1, y1, x2, y2);
  340.     }
  341.  
  342. DrawImages(Window, x, y)
  343. struct Window *Window;
  344. long int x, y;
  345.     {
  346.     USHORT *icon;
  347.     int loop;
  348.  
  349.     Icons.Height = ICONY;
  350.     Icons.Width  = ICONX;
  351.     Icons.PlanePick = 0x3;
  352.     Icons.PlaneOnOff = 0x0;
  353.  
  354.     icon = AllocMem( (long) sizeof(USHORT) * ICONY * Icons.Depth + 10,
  355.                                                                 MEMF_CHIP);
  356.  
  357.     Icons.ImageData = icon;
  358.  
  359.     for
  360.     (loop=0; loop < ICONY * Icons.Depth; loop++) icon[loop] = Zoom_Icon[loop];
  361.     DrawImage(Window->RPort, &Icons, x, y);
  362.  
  363.     y += ICONY + 2;
  364.     for
  365.     (loop=0; loop < ICONY * Icons.Depth; loop++) icon[loop] = Move_Icon[loop];
  366.     DrawImage(Window->RPort, &Icons, x, y);
  367.  
  368.     y += ICONY + 2;
  369.     for
  370.     (loop=0; loop<ICONY * Icons.Depth; loop++) icon[loop] = Command_Icon[loop];
  371.     DrawImage(Window->RPort, &Icons, x, y);
  372.  
  373.     y += ICONY + 2;
  374.     for
  375.     (loop=0; loop< ICONY * Icons.Depth; loop++) icon[loop] = Hidden_Icon[loop];
  376.     DrawImage(Window->RPort, &Icons, x, y);
  377.  
  378.     y += ICONY + 2;        /* future location of home icon    */
  379.     for
  380.     (loop=0; loop < ICONY * Icons.Depth; loop++) icon[loop] = Home_Icon[loop];
  381.     DrawImage(Window->RPort, &Icons, x, y);
  382.  
  383.     y += ICONY + 2;        /* future location of quit icon    */
  384.     for
  385.     (loop=0; loop < ICONY * Icons.Depth; loop++) icon[loop] = Quit_Icon[loop];
  386.     DrawImage(Window->RPort, &Icons, x, y);
  387.  
  388.     y += ICONY + 2;
  389.     for
  390.     (loop=0; loop < ICONY * Icons.Depth; loop++) icon[loop] = Help_Icon[loop];
  391.     DrawImage(Window->RPort, &Icons, x, y);
  392.  
  393.     FreeMem( icon, (long) sizeof(USHORT) * ICONY * Icons.Depth);
  394.     }
  395.  
  396. InvertIcon(Window, icon)
  397. struct Window *Window;
  398. long int icon;
  399.     {
  400.     long int x, y;
  401.     long int minx, miny, maxx, maxy;
  402.  
  403.     minx = Window->BorderLeft;
  404.     miny = Window->BorderTop;
  405.     maxx = Window->Width - Window->BorderRight - XBORDER;
  406.     maxy = Window->Height - Window->BorderBottom - YBORDER;
  407.  
  408.     SetDrMd(Window->RPort, COMPLEMENT);
  409.     SetAPen(Window->RPort, 3l);
  410.     SetOPen(Window->RPort, 0l);
  411.  
  412.     y = miny + YEXPANDY + (icon - 1) * (ICONY + 2);
  413.     RectFill(Window->RPort, maxx + YEXPANDX +2, y, maxx +XBORDER -1, y +ICONY);
  414.     }
  415.  
  416. DrawButton(Window, x, y)
  417. struct Window *Window;
  418. long int x,y;
  419.     {
  420.     long int minx, miny, maxx, maxy;
  421.  
  422.     SetDrMd(Window->RPort, JAM2);
  423.     SetAPen(Window->RPort, 2l);
  424.     SetOPen(Window->RPort, 2l);
  425.     RectFill(Window->RPort, x, y, x + BALLWIDTH - 1, y + BALLHEIGHT - 1);
  426.     }
  427.  
  428. EraseButton(Window, x, y)
  429. struct Window *Window;
  430. long int x,y;
  431.     {
  432.     long int minx, miny, maxx, maxy;
  433.  
  434.     SetDrMd(Window->RPort, JAM2);
  435.     SetAPen(Window->RPort, 0l);
  436.     SetOPen(Window->RPort, 0l);
  437.     RectFill(Window->RPort, x, y, x + BALLWIDTH - 1, y + BALLHEIGHT - 1);
  438.     }
  439.  
  440. swap (x1, x2)
  441. long int *x1, *x2;
  442.     {
  443.     long int tmp;
  444.     tmp = *x1;
  445.     *x1 = *x2;
  446.     *x2 = tmp;
  447.     }
  448.  
  449. Line(Window, colour, x1, y1, x2, y2)
  450. struct Window *Window;
  451. long int colour, x1, y1, x2, y2;
  452.     {
  453.     long int minx, miny, maxx, maxy;
  454.  
  455.     minx = Window->BorderLeft;
  456.     miny = Window->BorderTop;
  457.     maxx = Window->Width - Window->BorderRight - XBORDER;
  458.     maxy = Window->Height - Window->BorderBottom - YBORDER;
  459.  
  460. /* Clip the edges of the graph             */
  461. /* start with the horizontal borders    */
  462.     if (y1 >= miny && y1 <= maxy && y2 >= miny && y2 <= maxy);/* Do nothing    */
  463.     else if ( (y1 - miny) * (y2 - miny) < 0 )
  464.         {
  465.         /* Clip against top edge    */
  466.         if (y2 > miny) 
  467.             {
  468.             swap(&x1, &x2);
  469.             swap(&y1, &y2);
  470.             }
  471.         x2 = (miny - y1)*(x1-x2)/(y1-y2)+x1;
  472.         y2 = miny;
  473.         }
  474.     else if ( (y1 - maxy) * (y2 - maxy) < 0 )
  475.         {
  476.         /* Clip against bottom edge    */
  477.         if (y2 < maxy) 
  478.             {
  479.             swap(&x1, &x2);
  480.             swap(&y1, &y2);
  481.             }
  482.         x2 = (maxy - y1)*(x1-x2)/(y1-y2)+x1;
  483.         y2 = maxy;
  484.         }
  485.     else return();
  486.  
  487. /* and know the vertical edges        */
  488.     if (x1 >= minx && x1 <= maxx && x2 >= minx && x2 <= maxx);/* Do nothing    */
  489.     else if ( (x1 - minx) * (x2 - minx) < 0 )
  490.         {
  491.         /* Clip against top edge    */
  492.         if (x2 > minx) 
  493.             {
  494.             swap(&x1, &x2);
  495.             swap(&y1, &y2);
  496.             }
  497.         y2 = (minx - x1)*(y1-y2)/(x1-x2)+y1;
  498.         x2 = minx;
  499.         }
  500.     else if ( (x1 - maxx) * (x2 - maxx) < 0 )
  501.         {
  502.         /* Clip against bottom edge    */
  503.         if (x2 < maxx) 
  504.             {
  505.             swap(&x1, &x2);
  506.             swap(&y1, &y2);
  507.             }
  508.         y2 = (maxx - x1)*(y1-y2)/(x1-x2)+y1;
  509.         x2 = maxx;
  510.         }
  511.     else return();
  512.  
  513.     SetAPen(Window->RPort, colour);
  514.     Move(Window->RPort, x1, y1);
  515.     Draw(Window->RPort, x2, y2);
  516.     }
  517.  
  518. CrossHair(Window, x, y)
  519. struct Window *Window;
  520. long int x, y;
  521.     {
  522.     long int minx, miny, maxx, maxy;
  523.  
  524.     minx = Window->BorderLeft;
  525.     miny = Window->BorderTop;
  526.     maxx = Window->Width - Window->BorderRight - XBORDER;
  527.     maxy = Window->Height - Window->BorderBottom - YBORDER;
  528.  
  529.     SetDrMd(Window->RPort, COMPLEMENT);
  530.     Line(Window, 3l, x, miny, x, maxy);
  531.     Line(Window, 3l, minx, y, maxx, y);
  532.     SetDrMd(Window->RPort, JAM2);
  533.     }
  534.  
  535. Box(Window, deltax, deltay)
  536. struct Window *Window;
  537. long int deltax, deltay;
  538.     {
  539.     long int minx, miny, maxx, maxy;
  540.  
  541.     minx = Window->BorderLeft;
  542.     miny = Window->BorderTop;
  543.     maxx = Window->Width - Window->BorderRight - XBORDER;
  544.     maxy = Window->Height - Window->BorderBottom - YBORDER;
  545.  
  546.     SetDrMd(Window->RPort, COMPLEMENT);
  547.     if (deltax > 0) Line(Window, 3l, minx + deltax, miny, minx + deltax, maxy);
  548.     if (deltax < 0) Line(Window, 3l, maxx + deltax, miny, maxx + deltax, maxy);
  549.  
  550.     if (deltay > 0) Line(Window, 3l, minx, miny + deltay, maxx, miny + deltay);
  551.     if (deltay < 0) Line(Window, 3l, minx, maxy + deltay, maxx, maxy + deltay);
  552.  
  553.     SetDrMd(Window->RPort, JAM2);
  554.     }
  555.  
  556. DrawGrid(Window)
  557. struct Window *Window;
  558.     {
  559.     long int minx, miny, maxx, maxy;
  560.  
  561.     minx = Window->BorderLeft;
  562.     miny = Window->BorderTop;
  563.     maxx = Window->Width - Window->BorderRight - XBORDER;
  564.     maxy = Window->Height - Window->BorderBottom - YBORDER;
  565.  
  566.     SetDrMd(Window->RPort, COMPLEMENT);
  567.     Line(Window, 1l, maxx / 3, miny, maxx / 3, maxy);
  568.     Line(Window, 1l, maxx * 2/ 3, miny, maxx * 2 / 3, maxy);
  569.     Line(Window, 1l, minx, maxy / 3, maxx, maxy / 3);
  570.     Line(Window, 1l, minx, maxy * 2 / 3, maxx, maxy * 2 / 3);
  571.     SetDrMd(Window->RPort, JAM2);
  572.     }
  573.  
  574. Real(Window, parameters, x1, y1, x2, y2)
  575. struct Window *Window;
  576. struct Graph_Parameters *parameters;
  577. long int x1, y1, x2, y2;
  578.     {
  579.     long int minx, miny, maxx, maxy;
  580.     double xsize, ysize, xstart, ystart, xend, yend, xconversion, yconversion;
  581.  
  582.     if (x1 == x2 || y1 == y2) return();
  583.  
  584.     minx = Window->BorderLeft;
  585.     miny = Window->BorderTop;
  586.     maxx = Window->Width - Window->BorderRight - XBORDER;
  587.     maxy = Window->Height - Window->BorderBottom - YBORDER;
  588.  
  589.     x1 = x1 - minx;
  590.     x2 = x2 - minx;
  591.     y1 = y1 - miny;
  592.     y2 = y2 - miny;
  593.  
  594.     xsize = parameters->xend - parameters->xstart;
  595.     ysize = parameters->yend - parameters->ystart;
  596.  
  597.     xstart = parameters->xstart;
  598.     ystart = parameters->ystart;
  599.  
  600.     xend = parameters->xend;
  601.     yend = parameters->yend;
  602.  
  603.     xconversion = xsize /(maxx - minx);
  604.     yconversion = ysize /(maxy - miny);
  605.  
  606.     if (x1 > x2) swap (&x1, &x2);
  607.     if (y1 > y2) swap (&y1, &y2);
  608.  
  609.     parameters->xstart = xstart + xconversion * x1;
  610.     parameters->ystart = ystart + yconversion * y1;
  611.  
  612.     parameters->xend = xstart + xconversion * x2;
  613.     parameters->yend = ystart + yconversion * y2;
  614.     DrawWindow(Window, parameters);
  615.     }
  616.  
  617. Shift(Window, parameters, dx, dy)
  618. struct Window *Window;
  619. struct Graph_Parameters *parameters;
  620. long int dx, dy;
  621.     {
  622.     long int minx, miny, maxx, maxy;
  623.     double xsize, ysize, xstart, ystart, xend, yend, xconversion, yconversion;
  624.     double deltax, deltay;
  625.  
  626.     deltax = dx;
  627.     deltay = dy;
  628.  
  629.     minx = Window->BorderLeft;
  630.     miny = Window->BorderTop;
  631.     maxx = Window->Width - Window->BorderRight - XBORDER;
  632.     maxy = Window->Height - Window->BorderBottom - YBORDER;
  633.  
  634.     xsize = parameters->xend - parameters->xstart;
  635.     ysize = parameters->yend - parameters->ystart;
  636.  
  637.     xstart = parameters->xstart;
  638.     ystart = parameters->ystart;
  639.  
  640.     xend = parameters->xend;
  641.     yend = parameters->yend;
  642.  
  643.     xconversion = xsize /(maxx - minx);
  644.     yconversion = ysize /(maxy - miny);
  645.  
  646.     parameters->xstart = xstart + xconversion * deltax;
  647.     parameters->ystart = ystart + yconversion * deltay;
  648.  
  649.     parameters->xend = xend + xconversion * deltax;
  650.     parameters->yend = yend + yconversion * deltay;
  651.     }
  652.  
  653. /* define maximum number of menu items */
  654. #define MENU0MAX 4
  655. #define MENU1MAX 7
  656.  
  657. struct MenuItem ItemText0[MENU0MAX];
  658. struct MenuItem ItemText1[MENU1MAX];
  659. struct IntuiText MenuItem0[MENU0MAX];
  660. struct IntuiText MenuItem1[MENU1MAX];
  661.  
  662. InitMenu()
  663.     {
  664.     InitMenu0();
  665.     InitMenu1();
  666.  
  667.     menu[0].NextMenu = &menu[1];
  668.     menu[0].LeftEdge = 10;
  669.     menu[0].TopEdge = 0;
  670.     menu[0].Width = 80;
  671.     menu[0].Height = 10;
  672.     menu[0].Flags = MENUENABLED;
  673.     menu[0].MenuName = "Project";           /* text for menu-bar display */
  674.     menu[0].FirstItem = &ItemText0[0];    /* pointer to first item in list */
  675.  
  676.     menu[1].NextMenu = NULL;
  677.     menu[1].LeftEdge = 100;
  678.     menu[1].TopEdge = 0;
  679.     menu[1].Width = 100;
  680.     menu[1].Height = 10;
  681.     menu[1].Flags = MENUENABLED;
  682.     menu[1].MenuName = "Functions";        /* text for menu-bar display */
  683.     menu[1].FirstItem = &ItemText1[0];    /* pointer to first item in list */
  684.     }
  685.  
  686. InitMenu0()
  687.     {
  688.     short n;
  689.  
  690.     /* initialize each meu item and IntuiText with loop */
  691.     for( n=0; n<MENU1MAX; n++ )
  692.         {
  693.         ItemText0[n].NextItem = &ItemText0[n+1];
  694.         ItemText0[n].LeftEdge = 0;
  695.         ItemText0[n].TopEdge = 10 * n;
  696.         ItemText0[n].Width = 80;
  697.         ItemText0[n].Height = 10;
  698.         ItemText0[n].Flags = ITEMTEXT | ITEMENABLED | HIGHCOMP;
  699.         ItemText0[n].MutualExclude = 0;
  700.         ItemText0[n].ItemFill = (APTR)&MenuItem0[n];
  701.         ItemText0[n].SelectFill = NULL;
  702.         ItemText0[n].Command = 0;
  703.         ItemText0[n].SubItem = NULL;
  704.         ItemText0[n].NextSelect = 0;
  705.  
  706.         MenuItem0[n].FrontPen = 0;
  707.         MenuItem0[n].BackPen = 1;
  708.         MenuItem0[n].DrawMode = JAM2;     /* render in fore and background */
  709.         MenuItem0[n].LeftEdge = 0;
  710.         MenuItem0[n].TopEdge = 1;
  711.         MenuItem0[n].ITextFont = NULL;
  712.         MenuItem0[n].NextText = NULL;
  713.         }
  714.     ItemText0[MENU0MAX-1].NextItem = NULL;
  715.  
  716.     /* initialize text for specific menu items */
  717.     MenuItem0[0].IText = (UBYTE *)"Load";
  718.     MenuItem0[1].IText = (UBYTE *)"Save";
  719.     MenuItem0[2].IText = (UBYTE *)"About";
  720.     MenuItem0[3].IText = (UBYTE *)"Quit";
  721.     }
  722.  
  723. InitMenu1()
  724.     {
  725.     short n;
  726.  
  727.     /* initialize each meu item and IntuiText with loop */
  728.     for( n=0; n<MENU1MAX; n++ )
  729.         {
  730.         ItemText1[n].NextItem = &ItemText1[n+1];
  731.         ItemText1[n].LeftEdge = 0;
  732.         ItemText1[n].TopEdge = 10 * n;
  733.         ItemText1[n].Width = 120;
  734.         ItemText1[n].Height = 10;
  735.         ItemText1[n].Flags = ITEMTEXT | ITEMENABLED | HIGHCOMP;
  736.         ItemText1[n].MutualExclude = 0;
  737.         ItemText1[n].ItemFill = (APTR)&MenuItem1[n];
  738.         ItemText1[n].SelectFill = NULL;
  739.         ItemText1[n].Command = 0;
  740.         ItemText1[n].SubItem = NULL;
  741.         ItemText1[n].NextSelect = 0;
  742.  
  743.         MenuItem1[n].FrontPen = 0;
  744.         MenuItem1[n].BackPen = 1;
  745.         MenuItem1[n].DrawMode = JAM2;     /* render in fore and background */
  746.         MenuItem1[n].LeftEdge = 0;
  747.         MenuItem1[n].TopEdge = 1;
  748.         MenuItem1[n].ITextFont = NULL;
  749.         MenuItem1[n].NextText = NULL;
  750.         }
  751.     ItemText1[MENU1MAX-1].NextItem = NULL;
  752.  
  753.     /* initialize text for specific menu items */
  754.     MenuItem1[0].IText = (UBYTE *)"Zoom";
  755.     MenuItem1[1].IText = (UBYTE *)"Move";
  756.     MenuItem1[2].IText = (UBYTE *)"Command";
  757.     MenuItem1[3].IText = (UBYTE *)"Hidden Lines";
  758.     MenuItem1[4].IText = (UBYTE *)"Home";
  759.     MenuItem1[5].IText = (UBYTE *)"Quit";
  760.     MenuItem1[6].IText = (UBYTE *)"Help";
  761.     }
  762.